package com.kongjian.manage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.kongjian.manage.common.R;
import com.kongjian.manage.model.dto.NewWaterLevelRecordsDTO;
import com.kongjian.manage.model.dto.UpdateWaterLevelRecordsDTO;
import com.kongjian.manage.model.query.WaterLevelRecordsQuery;
import com.kongjian.manage.model.vo.WaterLevelRecordsVO;
import com.kongjian.manage.service.IWaterLevelRecordsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author tangjunfeng
 * @Classname WaterLevelRecordsController.java
 * @Description 水位记录表controller
 * @Date 2023-10-20
 * @Version V1.0
 */
@Api(tags = "水位记录表")
@RestController
@Validated
@RequestMapping("/api/v1/water-level-records")
public class WaterLevelRecordsController {


    @Autowired
    private IWaterLevelRecordsService waterLevelRecordsService;

    @ApiOperationSupport(order = 1)
    @GetMapping("page")
    @ApiOperation("查询")
    public R<Page> queryPageWaterLevelRecords(@ApiIgnore WaterLevelRecordsQuery query) throws Exception {
        return waterLevelRecordsService.queryPageWaterLevelRecords(query);
    }

    @ApiOperationSupport(order = 2)
    @GetMapping("count")
    @ApiOperation("统计")
    public Integer countWaterLevelRecords(WaterLevelRecordsQuery query) {
        return waterLevelRecordsService.countWaterLevelRecords(query);
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation("根据ID查询")
    @ApiImplicitParam(name = "id", value = "ID", dataType = "Long", example = "1", required = true)
    @GetMapping("/{id}")
    public WaterLevelRecordsVO getByIdWaterLevelRecords(@PathVariable("id") Long id) throws Exception {
        return waterLevelRecordsService.getByIdWaterLevelRecords(id);
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增")
    @PostMapping("")
    public R<String> addWaterLevelRecords(@RequestBody @Validated NewWaterLevelRecordsDTO waterLevelRecordsDTO) throws Exception {
        waterLevelRecordsService.addWaterLevelRecords(waterLevelRecordsDTO);
        return R.success("新增成功");
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation("更新")
    @ApiImplicitParam(name = "id", value = "ID", dataType = "Long", example = "1", required = true)
    @PutMapping("/{id}")
    public R<String> modifyWaterLevelRecords(@PathVariable("id") Long id, @Validated @RequestBody UpdateWaterLevelRecordsDTO waterLevelRecordsDTO) throws Exception {
        waterLevelRecordsService.modifyWaterLevelRecords(id, waterLevelRecordsDTO);
        return R.success("更新成功");
    }

    @ApiOperationSupport(order = 6)
    @ApiOperation("删除")
    @ApiImplicitParam(name = "id", value = "ID", dataType = "Long", example = "1", required = true)
    @DeleteMapping("/{id}")
    public R<String> deleteWaterLevelRecords(@PathVariable("id") Long id) throws Exception {
        waterLevelRecordsService.deleteWaterLevelRecords(id);
        return R.success("删除成功");
    }




}
